package com.cts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cts.entity.Category;
import com.cts.entity.Tag;
import com.cts.mapper.TagMapper;
import com.cts.model.dto.TagDTO;
import com.cts.model.vo.PageResultVO;
import com.cts.service.TagService;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author tongshengchen
* @description 针对表【tag】的数据库操作Service实现
* @createDate 2023-02-06 12:25:57
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag>
    implements TagService {

    @Autowired
    TagMapper tagMapper;

    @Override
    public PageResultVO<Tag> getTagList(TagDTO tagDTO ) {
        LambdaQueryWrapper<Tag> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(!StringUtils.isNullOrEmpty(tagDTO.getTagName()),Tag::getTagName, tagDTO.getTagName());
        Page<Tag> page = new Page<>(tagDTO.getPageNo(),tagDTO.getPageSize());
        IPage<Tag> tags = tagMapper.selectPage(page, lambdaQueryWrapper);
        return new PageResultVO(tags.getTotal(), tags.getRecords());
    }
}




